package com.example.demo;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class Login {

    @RequestMapping(value = "/login" ,method = RequestMethod.POST)
    public Boolean login(@RequestParam String userName, @RequestParam String password, HttpServletRequest request) {
        if (userName.equals("ml") && password.equals("ml")) {
            HttpSession session = request.getSession();
            session.setAttribute("userName",userName);
            return true;
        }
        return false;
    }

    @GetMapping("/getLoginUser")
    public String getLoginUser(HttpSession session) {
        if (session.getAttribute("userName" ) != null) {
            return (String) session.getAttribute("userName");
        }
        return "";
    }
}
